<?php

declare(strict_types=1);
namespace app\api\controller;


use app\api\validate\User as UserValidate;
use app\BaseController;
use think\exception\ValidateException;
use app\api\business\Sms as SmsBus;
class Sms extends BaseController
{
    public function code() :object{
        $phone_number = input('param.phone_number','','trim');
        $data = [
            'phone_number' => $phone_number
        ];
        try {
            validate(UserValidate::class)->scene("send_code")->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }

        if (SmsBus::sendCode($phone_number,4)){
            return show(config('status.success'),'发送验证码成功');
        }
        return show(config('status.error'),'发送验证码失败');
    }
}